﻿using WeDonekRpc.Helper;
using WeDonekRpc.Helper.Validate;

namespace Basic.FlowRemoteModel.EventTemplate.Model
{
    public class EventTemplateSet
    {
        [NullValidate("flow.inter.name.null")]
        [LenValidate("flow.inter.name.len", 2, 50)]
        public string InterName { get; set; }

        [EnumValidate("flow.inter.type.error", typeof(FlowInterType))]
        public FlowInterType InterType { get; set; }


        [EnumValidate("flow.inter.use.range.error", typeof(FlowEventType))]
        public FlowEventType UseRange { get; set; }

        [EntrustValidate("_Check")]
        [NullValidate("flow.inter.config.null")]
        public InterConfig InterConfig { get; set; }


        private void _Check ()
        {
            if ( this.InterType == FlowInterType.指令 )
            {
                if ( this.InterConfig.RpcConfig == null )
                {
                    throw new ErrorException("flow.inter.rpc.config.null");
                }
            }
            else if ( this.InterType == FlowInterType.Http )
            {
                if ( this.InterConfig.HttpConfig == null )
                {
                    throw new ErrorException("flow.inter.http.config.null");
                }
            }
            else if ( this.InterConfig.BroadcastConfig == null )
            {
                throw new ErrorException("flow.inter.broadcast.config.null");
            }
        }
    }
}
